class Solution {
public:
    bool backspaceCompare(string s, string t) {
        string rets;
        string rett;

        for(auto ch:s)
        {
            if(ch!='#') 
                rets.push_back(ch);
            else if(ch=='#'&&rets.size())
                rets.pop_back();
        }

        for(auto ch:t)
        {
            if(ch!='#') 
                rett.push_back(ch);
            else if(ch=='#'&&rett.size())
                rett.pop_back();
        }
        if(rett!=rets) return false;
        else return true;
    }
};
